import React from 'react';
import {Table, Card, DatePicker,Popconfirm} from 'antd';
import moment from 'moment'
import BBSService from '../../service/BBSService';
const { RangePicker} = DatePicker;
export default class BBSList extends React.Component {

    state = {
        title:'BBS评论列表',
        tableList:[],
        loading:false,
        BBSId:null
    };

    constructor(props) {
        super(props);
    }

    componentDidMount() {
        this.state.BBSId = this.props.match.params.id;
        this.fetch(this.state.BBSId);
    }

    //查询方法
    fetch(id) {
        this.setState({
            loading: true,
        });
        let query = 'topicId=='+id
        BBSService.getCommentByBBSId({query:query,size:1000}).done((res)=>{
            console.log(res.entity);
            this.setState({tableList:res.entity,loading: false});

        })
    }

    render() {
        return (
            <Card title={this.state.title} className="user">
                <Table
                    rowKey={record => record.id}
                    bordered={true}
                    loading={this.state.loading}
                    dataSource={this.state.tableList}
                    pagination={false}
                    columns={[
                        {title:"评论人", align:'center', dataIndex: 'creator', key: 'creator',width:200},
                        {title:"评论时间", align:'center', dataIndex: 'createTime', key: 'createTime', width:200,render : (text, record) => {
                            return (
                                <span>{record.createTime?moment(record.createTime).format('YYYY/MM/DD HH:mm:ss'):''}</span>
                            )
                        }},
                        {title:"评论内容", align:'center', dataIndex: 'content', key: 'content'},
                        {title:"操作", align:'center', dataIndex: 'operation', width:200, key: 'operation',
                            render : (text, record) => {
                                return (
                                    <div className='btn-cen-div'>
                                        <Popconfirm placement="top" okText="确认" cancelText="关闭" title="是否确定删除?" onConfirm={() =>{
                                            BBSService.deleteCommentOne(record.id).done(()=>{
                                                this.fetch(this.state.BBSId);
                                            })
                                        }}>
                                            <a>删除</a>
                                        </Popconfirm>
                                    </div>
                                )
                            }
                        },
                    ]}
                />
            </Card>
        )
    }
}